package com.thinkingstar.iads.projectcenter.controller;

import com.zhuozhengsoft.pageoffice.poserver.AdminSeal;
import org.nutz.boot.starter.WebServletFace;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;

/**
 * 注册com.zhuozhengsoft.pageoffice.poserver.AdminSeal
 *
 */
@IocBean
public class PoAdminSeal implements WebServletFace {
    
    @Inject
    protected PropertiesProxy conf;

    public String getName() {
        return "adminseal";
    }

    public String getPathSpec() {
        return "/adminseal.zz";
    }

    public String[] getPathSpecs() {
        return new String[] {getPathSpec(), "/loginseal.zz", "/sealimage.zz"};
    }

    public Servlet getServlet() {
        return new AdminSeal();
    }

    @Override
    public void setServletContext(ServletContext sc) {
        if (Strings.isBlank(sc.getInitParameter("adminseal-password"))) {
            sc.setInitParameter("adminseal-password", conf.get("pageoffice.seal.admin.password"));
        }
        if (Strings.isBlank(sc.getInitParameter("posealdb-driver"))) {
            sc.setInitParameter("posealdb-driver", conf.get("pageoffice.seal.db.driver", conf.get("jdbc.driverClass")));
        }
        if (Strings.isBlank(sc.getInitParameter("posealdb-url"))) {
            sc.setInitParameter("posealdb-url", conf.get("pageoffice.seal.db.url", conf.get("jdbc.url")));
        }
        if (Strings.isBlank(sc.getInitParameter("posealdb-username"))) {
            sc.setInitParameter("posealdb-username", conf.get("pageoffice.seal.db.username", conf.get("jdbc.username")));
        }
        if (Strings.isBlank(sc.getInitParameter("posealdb-password"))) {
            sc.setInitParameter("posealdb-password", conf.get("pageoffice.seal.db.password", conf.get("jdbc.password")));
        }
    }
}
